{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# HiddenLayer Graph Demo - PyTorch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torchvision.models\n",
    "import hiddenlayer as hl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## VGG16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
       " -->\n",
       "<!-- Title: %3 Pages: 1 -->\n",
       "<svg width=\"363pt\" height=\"1758pt\"\n",
       " viewBox=\"0.00 0.00 362.50 1758.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(72 1722)\">\n",
       "<title>%3</title>\n",
       "<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-72,36 -72,-1722 290.5,-1722 290.5,36 -72,36\"/>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[4]/outputs/37 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[4]/outputs/37</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"173.5,-1595 103.5,-1595 103.5,-1559 173.5,-1559 173.5,-1595\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-1574\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool2x2</text>\n",
       "</g>\n",
       "<!-- 11555482124523074803 -->\n",
       "<g id=\"node20\" class=\"node\">\n",
       "<title>11555482124523074803</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180.5,-1512 96.5,-1512 96.5,-1468 180.5,-1468 180.5,-1512\"/>\n",
       "<text text-anchor=\"start\" x=\"104.5\" y=\"-1496\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"165.5\" y=\"-1475\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x2</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[4]/outputs/37&#45;&gt;11555482124523074803 -->\n",
       "<g id=\"edge16\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[4]/outputs/37&#45;&gt;11555482124523074803</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1558.9735C138.5,-1548.3194 138.5,-1534.5175 138.5,-1522.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1522.0152 138.5,-1512.0153 135.0001,-1522.0153 142.0001,-1522.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"170.5\" y=\"-1533\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x64x112x112</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[9]/outputs/42 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[9]/outputs/42</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"173.5,-1421 103.5,-1421 103.5,-1385 173.5,-1385 173.5,-1421\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-1400\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool2x2</text>\n",
       "</g>\n",
       "<!-- 5438248061125954030 -->\n",
       "<g id=\"node21\" class=\"node\">\n",
       "<title>5438248061125954030</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180.5,-1338 96.5,-1338 96.5,-1294 180.5,-1294 180.5,-1338\"/>\n",
       "<text text-anchor=\"start\" x=\"104.5\" y=\"-1322\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"165.5\" y=\"-1301\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x3</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[9]/outputs/42&#45;&gt;5438248061125954030 -->\n",
       "<g id=\"edge18\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[9]/outputs/42&#45;&gt;5438248061125954030</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1384.9735C138.5,-1374.3194 138.5,-1360.5175 138.5,-1348.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1348.0152 138.5,-1338.0153 135.0001,-1348.0153 142.0001,-1348.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1359\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x128x56x56</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[16]/outputs/49 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[16]/outputs/49</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"173.5,-1247 103.5,-1247 103.5,-1211 173.5,-1211 173.5,-1247\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-1226\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool2x2</text>\n",
       "</g>\n",
       "<!-- 9462597557974236026 -->\n",
       "<g id=\"node22\" class=\"node\">\n",
       "<title>9462597557974236026</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180.5,-1164 96.5,-1164 96.5,-1120 180.5,-1120 180.5,-1164\"/>\n",
       "<text text-anchor=\"start\" x=\"104.5\" y=\"-1148\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"165.5\" y=\"-1127\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x3</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[16]/outputs/49&#45;&gt;9462597557974236026 -->\n",
       "<g id=\"edge20\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[16]/outputs/49&#45;&gt;9462597557974236026</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1210.9735C138.5,-1200.3194 138.5,-1186.5175 138.5,-1174.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1174.0152 138.5,-1164.0153 135.0001,-1174.0153 142.0001,-1174.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1185\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x256x28x28</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[23]/outputs/56 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[23]/outputs/56</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"173.5,-1073 103.5,-1073 103.5,-1037 173.5,-1037 173.5,-1073\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-1052\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool2x2</text>\n",
       "</g>\n",
       "<!-- 2825772861897787669 -->\n",
       "<g id=\"node23\" class=\"node\">\n",
       "<title>2825772861897787669</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180.5,-990 96.5,-990 96.5,-946 180.5,-946 180.5,-990\"/>\n",
       "<text text-anchor=\"start\" x=\"104.5\" y=\"-974\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"165.5\" y=\"-953\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x3</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[23]/outputs/56&#45;&gt;2825772861897787669 -->\n",
       "<g id=\"edge22\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[23]/outputs/56&#45;&gt;2825772861897787669</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1036.9735C138.5,-1026.3194 138.5,-1012.5175 138.5,-1000.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1000.0152 138.5,-990.0153 135.0001,-1000.0153 142.0001,-1000.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1011\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x14x14</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[30]/outputs/63 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[30]/outputs/63</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"173.5,-899 103.5,-899 103.5,-863 173.5,-863 173.5,-899\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-878\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool2x2</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/64 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>VGG/outputs/64</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"134.5,-816 80.5,-816 80.5,-780 134.5,-780 134.5,-816\"/>\n",
       "<text text-anchor=\"start\" x=\"95.5\" y=\"-795\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Shape</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[30]/outputs/63&#45;&gt;VGG/outputs/64 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[30]/outputs/63&#45;&gt;VGG/outputs/64</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M119.3132,-862.7524C114.9478,-857.4769 110.8947,-851.4007 108.5,-845 106.3381,-839.2215 105.3658,-832.7575 105.069,-826.5167\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"108.5695,-826.4013 105.1166,-816.3849 101.5696,-826.3684 108.5695,-826.4013\"/>\n",
       "<text text-anchor=\"middle\" x=\"132.5\" y=\"-837\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x7x7</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/71 -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>VGG/outputs/71</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"167.5,-451 113.5,-451 113.5,-415 167.5,-415 167.5,-451\"/>\n",
       "<text text-anchor=\"start\" x=\"123.5\" y=\"-430\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Reshape</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[features]/MaxPool2d[30]/outputs/63&#45;&gt;VGG/outputs/71 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>VGG/Sequential[features]/MaxPool2d[30]/outputs/63&#45;&gt;VGG/outputs/71</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M149.8721,-862.9787C159.0698,-846.6607 170.5,-821.6287 170.5,-798 170.5,-798 170.5,-798 170.5,-506 170.5,-490.0124 164.2679,-473.4338 157.4847,-460.1241\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"160.3992,-458.1589 152.5293,-451.0655 154.258,-461.5184 160.3992,-458.1589\"/>\n",
       "<text text-anchor=\"middle\" x=\"194.5\" y=\"-649.5\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x7x7</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/65 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>VGG/outputs/65</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"134.5,-743 80.5,-743 80.5,-707 134.5,-707 134.5,-743\"/>\n",
       "<text text-anchor=\"start\" x=\"97.5\" y=\"-722\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Slice</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/64&#45;&gt;VGG/outputs/65 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>VGG/outputs/64&#45;&gt;VGG/outputs/65</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M107.5,-779.9551C107.5,-771.8828 107.5,-762.1764 107.5,-753.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"111.0001,-753.0903 107.5,-743.0904 104.0001,-753.0904 111.0001,-753.0903\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/66 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>VGG/outputs/66</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"134.5,-670 80.5,-670 80.5,-634 134.5,-634 134.5,-670\"/>\n",
       "<text text-anchor=\"start\" x=\"90.5\" y=\"-649\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Squeeze</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/65&#45;&gt;VGG/outputs/66 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>VGG/outputs/65&#45;&gt;VGG/outputs/66</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M107.5,-706.9551C107.5,-698.8828 107.5,-689.1764 107.5,-680.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"111.0001,-680.0903 107.5,-670.0904 104.0001,-680.0904 111.0001,-680.0903\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/68 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>VGG/outputs/68</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"140,-597 79,-597 79,-561 140,-561 140,-597\"/>\n",
       "<text text-anchor=\"start\" x=\"87.5\" y=\"-576\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/66&#45;&gt;VGG/outputs/68 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>VGG/outputs/66&#45;&gt;VGG/outputs/68</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M107.9944,-633.9551C108.2155,-625.8828 108.4815,-616.1764 108.7279,-607.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"112.2291,-607.1825 109.0044,-597.0904 105.2317,-606.9907 112.2291,-607.1825\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/67 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>VGG/outputs/67</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"57.5,-670 3.5,-670 3.5,-634 57.5,-634 57.5,-670\"/>\n",
       "<text text-anchor=\"start\" x=\"12.5\" y=\"-649\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Constant</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/69 -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>VGG/outputs/69</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"61,-597 0,-597 0,-561 61,-561 61,-597\"/>\n",
       "<text text-anchor=\"start\" x=\"8.5\" y=\"-576\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/67&#45;&gt;VGG/outputs/69 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>VGG/outputs/67&#45;&gt;VGG/outputs/69</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M30.5,-633.9551C30.5,-625.8828 30.5,-616.1764 30.5,-607.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"34.0001,-607.0903 30.5,-597.0904 27.0001,-607.0904 34.0001,-607.0903\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/70 -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>VGG/outputs/70</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"136.5,-524 82.5,-524 82.5,-488 136.5,-488 136.5,-524\"/>\n",
       "<text text-anchor=\"start\" x=\"94.5\" y=\"-503\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Concat</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/68&#45;&gt;VGG/outputs/70 -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>VGG/outputs/68&#45;&gt;VGG/outputs/70</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M109.5,-560.9551C109.5,-552.8828 109.5,-543.1764 109.5,-534.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"113.0001,-534.0903 109.5,-524.0904 106.0001,-534.0904 113.0001,-534.0903\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/69&#45;&gt;VGG/outputs/70 -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>VGG/outputs/69&#45;&gt;VGG/outputs/70</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M50.0281,-560.9551C59.8083,-551.9177 71.8052,-540.8319 82.4561,-530.9899\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"84.9536,-533.4476 89.9228,-524.0904 80.2029,-528.3065 84.9536,-533.4476\"/>\n",
       "</g>\n",
       "<!-- VGG/outputs/70&#45;&gt;VGG/outputs/71 -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>VGG/outputs/70&#45;&gt;VGG/outputs/71</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M117.1629,-487.9551C120.7026,-479.6196 124.9823,-469.5416 128.9051,-460.3042\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"132.1306,-461.6629 132.8178,-451.0904 125.6874,-458.9267 132.1306,-461.6629\"/>\n",
       "</g>\n",
       "<!-- 17786792084392447177 -->\n",
       "<g id=\"node17\" class=\"node\">\n",
       "<title>17786792084392447177</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"176.5,-368 104.5,-368 104.5,-332 176.5,-332 176.5,-368\"/>\n",
       "<text text-anchor=\"start\" x=\"112.5\" y=\"-347\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Linear &gt; Relu</text>\n",
       "</g>\n",
       "<!-- VGG/outputs/71&#45;&gt;17786792084392447177 -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>VGG/outputs/71&#45;&gt;17786792084392447177</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M140.5,-414.9902C140.5,-404.2963 140.5,-390.4994 140.5,-378.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"144.0001,-378.2612 140.5,-368.2612 137.0001,-378.2613 144.0001,-378.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"159\" y=\"-389\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x25088</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[classifier]/Dropout[2]/outputs/74/75 -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>VGG/Sequential[classifier]/Dropout[2]/outputs/74/75</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"167.5,-285 113.5,-285 113.5,-249 167.5,-249 167.5,-285\"/>\n",
       "<text text-anchor=\"start\" x=\"123.5\" y=\"-264\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Dropout</text>\n",
       "</g>\n",
       "<!-- 5853362436630265667 -->\n",
       "<g id=\"node18\" class=\"node\">\n",
       "<title>5853362436630265667</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"176.5,-202 104.5,-202 104.5,-166 176.5,-166 176.5,-202\"/>\n",
       "<text text-anchor=\"start\" x=\"112.5\" y=\"-181\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Linear &gt; Relu</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[classifier]/Dropout[2]/outputs/74/75&#45;&gt;5853362436630265667 -->\n",
       "<g id=\"edge13\" class=\"edge\">\n",
       "<title>VGG/Sequential[classifier]/Dropout[2]/outputs/74/75&#45;&gt;5853362436630265667</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M140.5,-248.9902C140.5,-238.2963 140.5,-224.4994 140.5,-212.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"144.0001,-212.2612 140.5,-202.2612 137.0001,-212.2613 144.0001,-212.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"156.5\" y=\"-223\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x4096</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[classifier]/Dropout[5]/outputs/78/79 -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>VGG/Sequential[classifier]/Dropout[5]/outputs/78/79</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"167.5,-119 113.5,-119 113.5,-83 167.5,-83 167.5,-119\"/>\n",
       "<text text-anchor=\"start\" x=\"123.5\" y=\"-98\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Dropout</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[classifier]/Linear[6]/outputs/80 -->\n",
       "<g id=\"node16\" class=\"node\">\n",
       "<title>VGG/Sequential[classifier]/Linear[6]/outputs/80</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"167.5,-36 113.5,-36 113.5,0 167.5,0 167.5,-36\"/>\n",
       "<text text-anchor=\"start\" x=\"127.5\" y=\"-15\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Linear</text>\n",
       "</g>\n",
       "<!-- VGG/Sequential[classifier]/Dropout[5]/outputs/78/79&#45;&gt;VGG/Sequential[classifier]/Linear[6]/outputs/80 -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>VGG/Sequential[classifier]/Dropout[5]/outputs/78/79&#45;&gt;VGG/Sequential[classifier]/Linear[6]/outputs/80</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M140.5,-82.9902C140.5,-72.2963 140.5,-58.4994 140.5,-46.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"144.0001,-46.2612 140.5,-36.2612 137.0001,-46.2613 144.0001,-46.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"156.5\" y=\"-57\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x4096</text>\n",
       "</g>\n",
       "<!-- 17786792084392447177&#45;&gt;VGG/Sequential[classifier]/Dropout[2]/outputs/74/75 -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>17786792084392447177&#45;&gt;VGG/Sequential[classifier]/Dropout[2]/outputs/74/75</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M140.5,-331.9902C140.5,-321.2963 140.5,-307.4994 140.5,-295.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"144.0001,-295.2612 140.5,-285.2612 137.0001,-295.2613 144.0001,-295.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"156.5\" y=\"-306\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x4096</text>\n",
       "</g>\n",
       "<!-- 5853362436630265667&#45;&gt;VGG/Sequential[classifier]/Dropout[5]/outputs/78/79 -->\n",
       "<g id=\"edge14\" class=\"edge\">\n",
       "<title>5853362436630265667&#45;&gt;VGG/Sequential[classifier]/Dropout[5]/outputs/78/79</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M140.5,-165.9902C140.5,-155.2963 140.5,-141.4994 140.5,-129.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"144.0001,-129.2612 140.5,-119.2612 137.0001,-129.2613 144.0001,-129.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"156.5\" y=\"-140\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x4096</text>\n",
       "</g>\n",
       "<!-- 9729532047352963951 -->\n",
       "<g id=\"node19\" class=\"node\">\n",
       "<title>9729532047352963951</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180.5,-1686 96.5,-1686 96.5,-1642 180.5,-1642 180.5,-1686\"/>\n",
       "<text text-anchor=\"start\" x=\"104.5\" y=\"-1670\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"165.5\" y=\"-1649\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x2</text>\n",
       "</g>\n",
       "<!-- 9729532047352963951&#45;&gt;VGG/Sequential[features]/MaxPool2d[4]/outputs/37 -->\n",
       "<g id=\"edge15\" class=\"edge\">\n",
       "<title>9729532047352963951&#45;&gt;VGG/Sequential[features]/MaxPool2d[4]/outputs/37</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1641.5953C138.5,-1630.571 138.5,-1617.1615 138.5,-1605.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1605.2297 138.5,-1595.2298 135.0001,-1605.2298 142.0001,-1605.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"170.5\" y=\"-1616\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x64x224x224</text>\n",
       "</g>\n",
       "<!-- 11555482124523074803&#45;&gt;VGG/Sequential[features]/MaxPool2d[9]/outputs/42 -->\n",
       "<g id=\"edge17\" class=\"edge\">\n",
       "<title>11555482124523074803&#45;&gt;VGG/Sequential[features]/MaxPool2d[9]/outputs/42</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1467.5953C138.5,-1456.571 138.5,-1443.1615 138.5,-1431.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1431.2297 138.5,-1421.2298 135.0001,-1431.2298 142.0001,-1431.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"173\" y=\"-1442\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x128x112x112</text>\n",
       "</g>\n",
       "<!-- 5438248061125954030&#45;&gt;VGG/Sequential[features]/MaxPool2d[16]/outputs/49 -->\n",
       "<g id=\"edge19\" class=\"edge\">\n",
       "<title>5438248061125954030&#45;&gt;VGG/Sequential[features]/MaxPool2d[16]/outputs/49</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1293.5953C138.5,-1282.571 138.5,-1269.1615 138.5,-1257.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1257.2297 138.5,-1247.2298 135.0001,-1257.2298 142.0001,-1257.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1268\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x256x56x56</text>\n",
       "</g>\n",
       "<!-- 9462597557974236026&#45;&gt;VGG/Sequential[features]/MaxPool2d[23]/outputs/56 -->\n",
       "<g id=\"edge21\" class=\"edge\">\n",
       "<title>9462597557974236026&#45;&gt;VGG/Sequential[features]/MaxPool2d[23]/outputs/56</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-1119.5953C138.5,-1108.571 138.5,-1095.1615 138.5,-1083.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-1083.2297 138.5,-1073.2298 135.0001,-1083.2298 142.0001,-1083.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1094\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x28x28</text>\n",
       "</g>\n",
       "<!-- 2825772861897787669&#45;&gt;VGG/Sequential[features]/MaxPool2d[30]/outputs/63 -->\n",
       "<g id=\"edge23\" class=\"edge\">\n",
       "<title>2825772861897787669&#45;&gt;VGG/Sequential[features]/MaxPool2d[30]/outputs/63</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M138.5,-945.5953C138.5,-934.571 138.5,-921.1615 138.5,-909.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"142.0001,-909.2297 138.5,-899.2298 135.0001,-909.2298 142.0001,-909.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-920\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x14x14</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<hiddenlayer.graph.Graph at 0x7f1ce9e901d0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# VGG16 with BatchNorm\n",
    "model = torchvision.models.vgg16()\n",
    "\n",
    "# Build HiddenLayer graph\n",
    "# Jupyter Notebook renders it automatically\n",
    "hl.build_graph(model, torch.zeros([1, 3, 224, 224]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## AlexNet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
       " -->\n",
       "<!-- Title: %3 Pages: 1 -->\n",
       "<svg width=\"389pt\" height=\"1394pt\"\n",
       " viewBox=\"0.00 0.00 388.50 1394.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(72 1358)\">\n",
       "<title>%3</title>\n",
       "<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-72,36 -72,-1358 316.5,-1358 316.5,36 -72,36\"/>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"192.5,-1239 116.5,-1239 116.5,-1203 192.5,-1203 192.5,-1239\"/>\n",
       "<text text-anchor=\"start\" x=\"124.5\" y=\"-1218\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">MaxPool3x3</text>\n",
       "</g>\n",
       "<!-- 9648688765389405107 -->\n",
       "<g id=\"node16\" class=\"node\">\n",
       "<title>9648688765389405107</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"202,-1156 107,-1156 107,-1120 202,-1120 202,-1156\"/>\n",
       "<text text-anchor=\"start\" x=\"115.5\" y=\"-1135\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Conv5x5 &gt; Relu</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19&#45;&gt;9648688765389405107 -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19&#45;&gt;9648688765389405107</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M154.5,-1202.9902C154.5,-1192.2963 154.5,-1178.4994 154.5,-1166.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"158.0001,-1166.2612 154.5,-1156.2612 151.0001,-1166.2613 158.0001,-1166.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-1177\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x64x27x27</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"192.5,-1073 116.5,-1073 116.5,-1037 192.5,-1037 192.5,-1073\"/>\n",
       "<text text-anchor=\"start\" x=\"124.5\" y=\"-1052\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">MaxPool3x3</text>\n",
       "</g>\n",
       "<!-- 12076627962309283789 -->\n",
       "<g id=\"node19\" class=\"node\">\n",
       "<title>12076627962309283789</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"202,-990 107,-990 107,-946 202,-946 202,-990\"/>\n",
       "<text text-anchor=\"start\" x=\"115.5\" y=\"-974\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Conv3x3 &gt; Relu</text>\n",
       "<text text-anchor=\"start\" x=\"185.5\" y=\"-953\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">x3</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22&#45;&gt;12076627962309283789 -->\n",
       "<g id=\"edge18\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22&#45;&gt;12076627962309283789</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M154.5,-1036.9735C154.5,-1026.3194 154.5,-1012.5175 154.5,-1000.0623\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"158.0001,-1000.0152 154.5,-990.0153 151.0001,-1000.0153 158.0001,-1000.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"188\" y=\"-1011\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x192x13x13</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"192.5,-899 116.5,-899 116.5,-863 192.5,-863 192.5,-899\"/>\n",
       "<text text-anchor=\"start\" x=\"124.5\" y=\"-878\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">MaxPool3x3</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/30 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>AlexNet/outputs/30</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"148.5,-816 94.5,-816 94.5,-780 148.5,-780 148.5,-816\"/>\n",
       "<text text-anchor=\"start\" x=\"106.5\" y=\"-795\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Shape</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29&#45;&gt;AlexNet/outputs/30 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29&#45;&gt;AlexNet/outputs/30</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M132.34,-862.7933C127.5288,-857.5984 123.1044,-851.5507 120.5,-845 118.2206,-839.2669 117.3746,-832.8214 117.3142,-826.5842\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"120.8172,-826.6145 117.8397,-816.4466 113.8266,-826.252 120.8172,-826.6145\"/>\n",
       "<text text-anchor=\"middle\" x=\"148\" y=\"-837\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x256x6x6</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/37 -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>AlexNet/outputs/37</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"186.5,-451 128.5,-451 128.5,-415 186.5,-415 186.5,-451\"/>\n",
       "<text text-anchor=\"start\" x=\"136.5\" y=\"-430\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Reshape</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29&#45;&gt;AlexNet/outputs/37 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29&#45;&gt;AlexNet/outputs/37</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M167.1358,-862.8043C177.1611,-846.5743 189.5,-821.7705 189.5,-798 189.5,-798 189.5,-798 189.5,-506 189.5,-489.9655 182.9438,-473.4903 175.7666,-460.2586\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"178.5753,-458.1268 170.5156,-451.2498 172.5276,-461.6518 178.5753,-458.1268\"/>\n",
       "<text text-anchor=\"middle\" x=\"217\" y=\"-649.5\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x256x6x6</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/31 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>AlexNet/outputs/31</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"150.5,-743 96.5,-743 96.5,-707 150.5,-707 150.5,-743\"/>\n",
       "<text text-anchor=\"start\" x=\"111.5\" y=\"-722\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Slice</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/30&#45;&gt;AlexNet/outputs/31 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>AlexNet/outputs/30&#45;&gt;AlexNet/outputs/31</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M121.9944,-779.9551C122.2155,-771.8828 122.4815,-762.1764 122.7279,-753.1817\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"126.2291,-753.1825 123.0044,-743.0904 119.2317,-752.9907 126.2291,-753.1825\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/32 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>AlexNet/outputs/32</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"152.5,-670 94.5,-670 94.5,-634 152.5,-634 152.5,-670\"/>\n",
       "<text text-anchor=\"start\" x=\"102.5\" y=\"-649\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Squeeze</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/31&#45;&gt;AlexNet/outputs/32 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>AlexNet/outputs/31&#45;&gt;AlexNet/outputs/32</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M123.5,-706.9551C123.5,-698.8828 123.5,-689.1764 123.5,-680.1817\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"127.0001,-680.0903 123.5,-670.0904 120.0001,-680.0904 127.0001,-680.0903\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/34 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>AlexNet/outputs/34</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"160,-597 89,-597 89,-561 160,-561 160,-597\"/>\n",
       "<text text-anchor=\"start\" x=\"97.5\" y=\"-576\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/32&#45;&gt;AlexNet/outputs/34 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>AlexNet/outputs/32&#45;&gt;AlexNet/outputs/34</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M123.7472,-633.9551C123.8578,-625.8828 123.9907,-616.1764 124.1139,-607.1817\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"127.6148,-607.1374 124.2522,-597.0904 120.6154,-607.0414 127.6148,-607.1374\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/33 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>AlexNet/outputs/33</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"65.5,-670 5.5,-670 5.5,-634 65.5,-634 65.5,-670\"/>\n",
       "<text text-anchor=\"start\" x=\"13.5\" y=\"-649\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Constant</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/35 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>AlexNet/outputs/35</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"71,-597 0,-597 0,-561 71,-561 71,-597\"/>\n",
       "<text text-anchor=\"start\" x=\"8.5\" y=\"-576\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/33&#45;&gt;AlexNet/outputs/35 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>AlexNet/outputs/33&#45;&gt;AlexNet/outputs/35</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M35.5,-633.9551C35.5,-625.8828 35.5,-616.1764 35.5,-607.1817\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"39.0001,-607.0903 35.5,-597.0904 32.0001,-607.0904 39.0001,-607.0903\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/36 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>AlexNet/outputs/36</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"151.5,-524 97.5,-524 97.5,-488 151.5,-488 151.5,-524\"/>\n",
       "<text text-anchor=\"start\" x=\"107.5\" y=\"-503\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Concat</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/34&#45;&gt;AlexNet/outputs/36 -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>AlexNet/outputs/34&#45;&gt;AlexNet/outputs/36</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M124.5,-560.9551C124.5,-552.8828 124.5,-543.1764 124.5,-534.1817\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"128.0001,-534.0903 124.5,-524.0904 121.0001,-534.0904 128.0001,-534.0903\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/35&#45;&gt;AlexNet/outputs/36 -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>AlexNet/outputs/35&#45;&gt;AlexNet/outputs/36</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M57.5,-560.9551C68.6251,-551.8299 82.2964,-540.6165 94.3819,-530.7036\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"96.9324,-533.1384 102.4446,-524.0904 92.4931,-527.7261 96.9324,-533.1384\"/>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/36&#45;&gt;AlexNet/outputs/37 -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>AlexNet/outputs/36&#45;&gt;AlexNet/outputs/37</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M132.6573,-487.9551C136.4254,-479.6196 140.9812,-469.5416 145.157,-460.3042\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"148.3922,-461.6443 149.3222,-451.0904 142.0136,-458.7608 148.3922,-461.6443\"/>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39 -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"185.5,-368 129.5,-368 129.5,-332 185.5,-332 185.5,-368\"/>\n",
       "<text text-anchor=\"start\" x=\"137.5\" y=\"-347\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Dropout</text>\n",
       "</g>\n",
       "<!-- AlexNet/outputs/37&#45;&gt;AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39 -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>AlexNet/outputs/37&#45;&gt;AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M157.5,-414.9902C157.5,-404.2963 157.5,-390.4994 157.5,-378.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"161.0001,-378.2612 157.5,-368.2612 154.0001,-378.2613 161.0001,-378.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"176\" y=\"-389\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x9216</text>\n",
       "</g>\n",
       "<!-- 2688423232248073962 -->\n",
       "<g id=\"node17\" class=\"node\">\n",
       "<title>2688423232248073962</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"198.5,-285 116.5,-285 116.5,-249 198.5,-249 198.5,-285\"/>\n",
       "<text text-anchor=\"start\" x=\"124.5\" y=\"-264\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Linear &gt; Relu</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39&#45;&gt;2688423232248073962 -->\n",
       "<g id=\"edge14\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[classifier]/Dropout[0]/outputs/38/39&#45;&gt;2688423232248073962</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M157.5,-331.9902C157.5,-321.2963 157.5,-307.4994 157.5,-295.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"161.0001,-295.2612 157.5,-285.2612 154.0001,-295.2613 161.0001,-295.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"176\" y=\"-306\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x9216</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43 -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"185.5,-202 129.5,-202 129.5,-166 185.5,-166 185.5,-202\"/>\n",
       "<text text-anchor=\"start\" x=\"137.5\" y=\"-181\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Dropout</text>\n",
       "</g>\n",
       "<!-- 16722201306697955387 -->\n",
       "<g id=\"node18\" class=\"node\">\n",
       "<title>16722201306697955387</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"198.5,-119 116.5,-119 116.5,-83 198.5,-83 198.5,-119\"/>\n",
       "<text text-anchor=\"start\" x=\"124.5\" y=\"-98\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Linear &gt; Relu</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43&#45;&gt;16722201306697955387 -->\n",
       "<g id=\"edge16\" class=\"edge\">\n",
       "<title>AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43&#45;&gt;16722201306697955387</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M157.5,-165.9902C157.5,-155.2963 157.5,-141.4994 157.5,-129.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"161.0001,-129.2612 157.5,-119.2612 154.0001,-129.2613 161.0001,-129.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"176\" y=\"-140\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x4096</text>\n",
       "</g>\n",
       "<!-- AlexNet/Sequential[classifier]/Linear[6]/outputs/46 -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>AlexNet/Sequential[classifier]/Linear[6]/outputs/46</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"184.5,-36 130.5,-36 130.5,0 184.5,0 184.5,-36\"/>\n",
       "<text text-anchor=\"start\" x=\"142.5\" y=\"-15\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Linear</text>\n",
       "</g>\n",
       "<!-- 12393879333135588649 -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>12393879333135588649</title>\n",
       "<polygon fill=\"#bcd6fc\" stroke=\"#7c96bc\" points=\"208,-1322 101,-1322 101,-1286 208,-1286 208,-1322\"/>\n",
       "<text text-anchor=\"start\" x=\"109.5\" y=\"-1301\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">Conv11x11 &gt; Relu</text>\n",
       "</g>\n",
       "<!-- 12393879333135588649&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19 -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>12393879333135588649&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[2]/outputs/19</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M154.5,-1285.9902C154.5,-1275.2963 154.5,-1261.4994 154.5,-1249.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"158.0001,-1249.2612 154.5,-1239.2612 151.0001,-1249.2613 158.0001,-1249.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-1260\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x64x55x55</text>\n",
       "</g>\n",
       "<!-- 9648688765389405107&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22 -->\n",
       "<g id=\"edge13\" class=\"edge\">\n",
       "<title>9648688765389405107&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[5]/outputs/22</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M154.5,-1119.9902C154.5,-1109.2963 154.5,-1095.4994 154.5,-1083.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"158.0001,-1083.2612 154.5,-1073.2612 151.0001,-1083.2613 158.0001,-1083.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"188\" y=\"-1094\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x192x27x27</text>\n",
       "</g>\n",
       "<!-- 2688423232248073962&#45;&gt;AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43 -->\n",
       "<g id=\"edge15\" class=\"edge\">\n",
       "<title>2688423232248073962&#45;&gt;AlexNet/Sequential[classifier]/Dropout[3]/outputs/42/43</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M157.5,-248.9902C157.5,-238.2963 157.5,-224.4994 157.5,-212.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"161.0001,-212.2612 157.5,-202.2612 154.0001,-212.2613 161.0001,-212.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"176\" y=\"-223\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x4096</text>\n",
       "</g>\n",
       "<!-- 16722201306697955387&#45;&gt;AlexNet/Sequential[classifier]/Linear[6]/outputs/46 -->\n",
       "<g id=\"edge17\" class=\"edge\">\n",
       "<title>16722201306697955387&#45;&gt;AlexNet/Sequential[classifier]/Linear[6]/outputs/46</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M157.5,-82.9902C157.5,-72.2963 157.5,-58.4994 157.5,-46.3706\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"161.0001,-46.2612 157.5,-36.2612 154.0001,-46.2613 161.0001,-46.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"176\" y=\"-57\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x4096</text>\n",
       "</g>\n",
       "<!-- 12076627962309283789&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29 -->\n",
       "<g id=\"edge19\" class=\"edge\">\n",
       "<title>12076627962309283789&#45;&gt;AlexNet/Sequential[features]/MaxPool2d[12]/outputs/29</title>\n",
       "<path fill=\"none\" stroke=\"#7c96bc\" d=\"M154.5,-945.5953C154.5,-934.571 154.5,-921.1615 154.5,-909.4234\"/>\n",
       "<polygon fill=\"#7c96bc\" stroke=\"#7c96bc\" points=\"158.0001,-909.2297 154.5,-899.2298 151.0001,-909.2298 158.0001,-909.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"188\" y=\"-920\" font-family=\"Verdana\" font-size=\"10.00\" fill=\"#202020\">1x384x13x13</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<hiddenlayer.graph.Graph at 0x7f1ce9e29f98>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# AlexNet\n",
    "model = torchvision.models.alexnet()\n",
    "\n",
    "# Build HiddenLayer graph\n",
    "hl_graph = hl.build_graph(model, torch.zeros([1, 3, 224, 224]))\n",
    "\n",
    "# Use a different color theme\n",
    "hl_graph.theme = hl.graph.THEMES[\"blue\"].copy()  # Two options: basic and blue\n",
    "hl_graph"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Transforms and Graph Expressions\n",
    "\n",
    "A Graph Expression is like a Regular Expression for graphs. It simplifies searching for nodes that fit a particular pattern. For example, the graph expression `Conv > Relu` will find Conv layers that are followed by RELU layers. And the expressions `Conv | MaxPool` will match any Conv and MaxPool layers that are in parallel branches (i.e. have the same parent node). See examples of more complex graph expressions below.\n",
    "\n",
    "Once the graph expression finds the nodes, we use Transforms to modify them. For example, if we want to delete all nodes of type `Const`, we'll use the transform `Prune(\"Const\")`. The graph expression here is simple, `Const`, which matches any node with operation of type Const. And the Prune() transform deletes the node.\n",
    "\n",
    "See more examples below. And, also, check `SIMPLICITY_TRANSFORMS` in `transforms.py`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ResNet101\n",
    "\n",
    "ResNet101 is a large network, but it consists of repetitive patterns. To simplify drawing the graph, we define our own transforms that find Residual Blocks and folds them together. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
       " -->\n",
       "<!-- Title: %3 Pages: 1 -->\n",
       "<svg width=\"367pt\" height=\"1574pt\"\n",
       " viewBox=\"0.00 0.00 366.50 1574.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(72 1538)\">\n",
       "<title>%3</title>\n",
       "<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-72,36 -72,-1538 294.5,-1538 294.5,36 -72,36\"/>\n",
       "<!-- ResNet/MaxPool2d[maxpool]/outputs/634 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>ResNet/MaxPool2d[maxpool]/outputs/634</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"170.5,-1419 100.5,-1419 100.5,-1383 170.5,-1383 170.5,-1419\"/>\n",
       "<text text-anchor=\"start\" x=\"108.5\" y=\"-1398\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">MaxPool3x3</text>\n",
       "</g>\n",
       "<!-- 17078548872372858591 -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>17078548872372858591</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180,-1336 91,-1336 91,-1300 180,-1300 180,-1336\"/>\n",
       "<text text-anchor=\"start\" x=\"99.5\" y=\"-1315\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Bottleneck Block</text>\n",
       "</g>\n",
       "<!-- ResNet/MaxPool2d[maxpool]/outputs/634&#45;&gt;17078548872372858591 -->\n",
       "<g id=\"edge13\" class=\"edge\">\n",
       "<title>ResNet/MaxPool2d[maxpool]/outputs/634&#45;&gt;17078548872372858591</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1382.9902C135.5,-1372.2963 135.5,-1358.4994 135.5,-1346.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-1346.2612 135.5,-1336.2612 132.0001,-1346.2613 139.0001,-1346.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"162\" y=\"-1357\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x64x56x56</text>\n",
       "</g>\n",
       "<!-- ResNet/AvgPool2d[avgpool]/outputs/1385 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>ResNet/AvgPool2d[avgpool]/outputs/1385</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"162.5,-640 108.5,-640 108.5,-604 162.5,-604 162.5,-640\"/>\n",
       "<text text-anchor=\"start\" x=\"127.5\" y=\"-619\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Pad</text>\n",
       "</g>\n",
       "<!-- ResNet/AvgPool2d[avgpool]/outputs/1386 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>ResNet/AvgPool2d[avgpool]/outputs/1386</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"177.5,-567 93.5,-567 93.5,-531 177.5,-531 177.5,-567\"/>\n",
       "<text text-anchor=\"start\" x=\"101.5\" y=\"-546\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">AveragePool7x7</text>\n",
       "</g>\n",
       "<!-- ResNet/AvgPool2d[avgpool]/outputs/1385&#45;&gt;ResNet/AvgPool2d[avgpool]/outputs/1386 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>ResNet/AvgPool2d[avgpool]/outputs/1385&#45;&gt;ResNet/AvgPool2d[avgpool]/outputs/1386</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-603.9551C135.5,-595.8828 135.5,-586.1764 135.5,-577.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-577.0903 135.5,-567.0904 132.0001,-577.0904 139.0001,-577.0903\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1387 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>ResNet/outputs/1387</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"129.5,-484 75.5,-484 75.5,-448 129.5,-448 129.5,-484\"/>\n",
       "<text text-anchor=\"start\" x=\"90.5\" y=\"-463\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Shape</text>\n",
       "</g>\n",
       "<!-- ResNet/AvgPool2d[avgpool]/outputs/1386&#45;&gt;ResNet/outputs/1387 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>ResNet/AvgPool2d[avgpool]/outputs/1386&#45;&gt;ResNet/outputs/1387</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M113.9815,-530.6947C109.312,-525.5016 105.0204,-519.4795 102.5,-513 100.2639,-507.2514 99.3483,-500.7996 99.1685,-494.5611\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"102.671,-494.5211 99.4571,-484.4255 95.6738,-494.3218 102.671,-494.5211\"/>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-505\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x2048x1x1</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1394 -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>ResNet/outputs/1394</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"166.5,-119 112.5,-119 112.5,-83 166.5,-83 166.5,-119\"/>\n",
       "<text text-anchor=\"start\" x=\"122.5\" y=\"-98\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Reshape</text>\n",
       "</g>\n",
       "<!-- ResNet/AvgPool2d[avgpool]/outputs/1386&#45;&gt;ResNet/outputs/1394 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>ResNet/AvgPool2d[avgpool]/outputs/1386&#45;&gt;ResNet/outputs/1394</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M147.7748,-530.7541C157.5137,-514.492 169.5,-489.6692 169.5,-466 169.5,-466 169.5,-466 169.5,-174 169.5,-158.0124 163.2679,-141.4338 156.4847,-128.1241\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"159.3992,-126.1589 151.5293,-119.0655 153.258,-129.5184 159.3992,-126.1589\"/>\n",
       "<text text-anchor=\"middle\" x=\"196\" y=\"-317.5\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x2048x1x1</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1388 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>ResNet/outputs/1388</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"130.5,-411 76.5,-411 76.5,-375 130.5,-375 130.5,-411\"/>\n",
       "<text text-anchor=\"start\" x=\"93.5\" y=\"-390\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Slice</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1387&#45;&gt;ResNet/outputs/1388 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>ResNet/outputs/1387&#45;&gt;ResNet/outputs/1388</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M102.7472,-447.9551C102.8578,-439.8828 102.9907,-430.1764 103.1139,-421.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"106.6148,-421.1374 103.2522,-411.0904 99.6154,-421.0414 106.6148,-421.1374\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1389 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>ResNet/outputs/1389</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"130.5,-338 76.5,-338 76.5,-302 130.5,-302 130.5,-338\"/>\n",
       "<text text-anchor=\"start\" x=\"86.5\" y=\"-317\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Squeeze</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1388&#45;&gt;ResNet/outputs/1389 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>ResNet/outputs/1388&#45;&gt;ResNet/outputs/1389</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M103.5,-374.9551C103.5,-366.8828 103.5,-357.1764 103.5,-348.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"107.0001,-348.0903 103.5,-338.0904 100.0001,-348.0904 107.0001,-348.0903\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1391 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>ResNet/outputs/1391</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"140,-265 79,-265 79,-229 140,-229 140,-265\"/>\n",
       "<text text-anchor=\"start\" x=\"87.5\" y=\"-244\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1389&#45;&gt;ResNet/outputs/1391 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>ResNet/outputs/1389&#45;&gt;ResNet/outputs/1391</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M104.9831,-301.9551C105.6466,-293.8828 106.4444,-284.1764 107.1837,-275.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"110.6821,-275.3435 108.0131,-265.0904 103.7056,-274.77 110.6821,-275.3435\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1390 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>ResNet/outputs/1390</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"57.5,-338 3.5,-338 3.5,-302 57.5,-302 57.5,-338\"/>\n",
       "<text text-anchor=\"start\" x=\"12.5\" y=\"-317\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Constant</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1392 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>ResNet/outputs/1392</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"61,-265 0,-265 0,-229 61,-229 61,-265\"/>\n",
       "<text text-anchor=\"start\" x=\"8.5\" y=\"-244\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Unsqueeze</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1390&#45;&gt;ResNet/outputs/1392 -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>ResNet/outputs/1390&#45;&gt;ResNet/outputs/1392</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M30.5,-301.9551C30.5,-293.8828 30.5,-284.1764 30.5,-275.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"34.0001,-275.0903 30.5,-265.0904 27.0001,-275.0904 34.0001,-275.0903\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1393 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>ResNet/outputs/1393</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"136.5,-192 82.5,-192 82.5,-156 136.5,-156 136.5,-192\"/>\n",
       "<text text-anchor=\"start\" x=\"94.5\" y=\"-171\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Concat</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1391&#45;&gt;ResNet/outputs/1393 -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>ResNet/outputs/1391&#45;&gt;ResNet/outputs/1393</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M109.5,-228.9551C109.5,-220.8828 109.5,-211.1764 109.5,-202.1817\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"113.0001,-202.0903 109.5,-192.0904 106.0001,-202.0904 113.0001,-202.0903\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1392&#45;&gt;ResNet/outputs/1393 -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>ResNet/outputs/1392&#45;&gt;ResNet/outputs/1393</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M50.0281,-228.9551C59.8083,-219.9177 71.8052,-208.8319 82.4561,-198.9899\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"84.9536,-201.4476 89.9228,-192.0904 80.2029,-196.3065 84.9536,-201.4476\"/>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1393&#45;&gt;ResNet/outputs/1394 -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>ResNet/outputs/1393&#45;&gt;ResNet/outputs/1394</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M116.9157,-155.9551C120.3052,-147.7074 124.3958,-137.7536 128.1591,-128.5962\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"131.5017,-129.6702 132.0656,-119.0904 125.0271,-127.0094 131.5017,-129.6702\"/>\n",
       "</g>\n",
       "<!-- ResNet/Linear[fc]/outputs/1395 -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>ResNet/Linear[fc]/outputs/1395</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"166.5,-36 112.5,-36 112.5,0 166.5,0 166.5,-36\"/>\n",
       "<text text-anchor=\"start\" x=\"126.5\" y=\"-15\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Linear</text>\n",
       "</g>\n",
       "<!-- ResNet/outputs/1394&#45;&gt;ResNet/Linear[fc]/outputs/1395 -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>ResNet/outputs/1394&#45;&gt;ResNet/Linear[fc]/outputs/1395</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M139.5,-82.9902C139.5,-72.2963 139.5,-58.4994 139.5,-46.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"143.0001,-46.2612 139.5,-36.2612 136.0001,-46.2613 143.0001,-46.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"155.5\" y=\"-57\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x2048</text>\n",
       "</g>\n",
       "<!-- 14512332594469533187 -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>14512332594469533187</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"205.5,-1502 65.5,-1502 65.5,-1466 205.5,-1466 205.5,-1502\"/>\n",
       "<text text-anchor=\"start\" x=\"73.5\" y=\"-1481\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Conv7x7 &gt; BatchNorm &gt; Relu</text>\n",
       "</g>\n",
       "<!-- 14512332594469533187&#45;&gt;ResNet/MaxPool2d[maxpool]/outputs/634 -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>14512332594469533187&#45;&gt;ResNet/MaxPool2d[maxpool]/outputs/634</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1465.9902C135.5,-1455.2963 135.5,-1441.4994 135.5,-1429.3706\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-1429.2612 135.5,-1419.2612 132.0001,-1429.2613 139.0001,-1429.2612\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-1440\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x64x112x112</text>\n",
       "</g>\n",
       "<!-- 758937017038444827 -->\n",
       "<g id=\"node18\" class=\"node\">\n",
       "<title>758937017038444827</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"175.5,-1253 95.5,-1253 95.5,-1209 175.5,-1209 175.5,-1253\"/>\n",
       "<text text-anchor=\"start\" x=\"103.5\" y=\"-1237\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Residual Block</text>\n",
       "<text text-anchor=\"start\" x=\"160.5\" y=\"-1216\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x2</text>\n",
       "</g>\n",
       "<!-- 17078548872372858591&#45;&gt;758937017038444827 -->\n",
       "<g id=\"edge14\" class=\"edge\">\n",
       "<title>17078548872372858591&#45;&gt;758937017038444827</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1299.9735C135.5,-1289.3194 135.5,-1275.5175 135.5,-1263.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-1263.0152 135.5,-1253.0153 132.0001,-1263.0153 139.0001,-1263.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-1274\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x256x56x56</text>\n",
       "</g>\n",
       "<!-- 210403017578684015 -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>210403017578684015</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180,-1162 91,-1162 91,-1126 180,-1126 180,-1162\"/>\n",
       "<text text-anchor=\"start\" x=\"99.5\" y=\"-1141\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Bottleneck Block</text>\n",
       "</g>\n",
       "<!-- 2760642466268956175 -->\n",
       "<g id=\"node20\" class=\"node\">\n",
       "<title>2760642466268956175</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"175.5,-1079 95.5,-1079 95.5,-1035 175.5,-1035 175.5,-1079\"/>\n",
       "<text text-anchor=\"start\" x=\"103.5\" y=\"-1063\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Residual Block</text>\n",
       "<text text-anchor=\"start\" x=\"160.5\" y=\"-1042\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x3</text>\n",
       "</g>\n",
       "<!-- 210403017578684015&#45;&gt;2760642466268956175 -->\n",
       "<g id=\"edge18\" class=\"edge\">\n",
       "<title>210403017578684015&#45;&gt;2760642466268956175</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1125.9735C135.5,-1115.3194 135.5,-1101.5175 135.5,-1089.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-1089.0152 135.5,-1079.0153 132.0001,-1089.0153 139.0001,-1089.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-1100\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x28x28</text>\n",
       "</g>\n",
       "<!-- 16222374167483738286 -->\n",
       "<g id=\"node16\" class=\"node\">\n",
       "<title>16222374167483738286</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180,-988 91,-988 91,-952 180,-952 180,-988\"/>\n",
       "<text text-anchor=\"start\" x=\"99.5\" y=\"-967\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Bottleneck Block</text>\n",
       "</g>\n",
       "<!-- 17791055073794206932 -->\n",
       "<g id=\"node21\" class=\"node\">\n",
       "<title>17791055073794206932</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"175.5,-905 95.5,-905 95.5,-861 175.5,-861 175.5,-905\"/>\n",
       "<text text-anchor=\"start\" x=\"103.5\" y=\"-889\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Residual Block</text>\n",
       "<text text-anchor=\"start\" x=\"155.5\" y=\"-868\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x22</text>\n",
       "</g>\n",
       "<!-- 16222374167483738286&#45;&gt;17791055073794206932 -->\n",
       "<g id=\"edge20\" class=\"edge\">\n",
       "<title>16222374167483738286&#45;&gt;17791055073794206932</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-951.9735C135.5,-941.3194 135.5,-927.5175 135.5,-915.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-915.0152 135.5,-905.0153 132.0001,-915.0153 139.0001,-915.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-926\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x1024x14x14</text>\n",
       "</g>\n",
       "<!-- 6818277186344059326 -->\n",
       "<g id=\"node17\" class=\"node\">\n",
       "<title>6818277186344059326</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"180,-814 91,-814 91,-778 180,-778 180,-814\"/>\n",
       "<text text-anchor=\"start\" x=\"99.5\" y=\"-793\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Bottleneck Block</text>\n",
       "</g>\n",
       "<!-- 9704017862113085769 -->\n",
       "<g id=\"node19\" class=\"node\">\n",
       "<title>9704017862113085769</title>\n",
       "<polygon fill=\"#e8e8e8\" stroke=\"#000000\" points=\"175.5,-731 95.5,-731 95.5,-687 175.5,-687 175.5,-731\"/>\n",
       "<text text-anchor=\"start\" x=\"103.5\" y=\"-715\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">Residual Block</text>\n",
       "<text text-anchor=\"start\" x=\"160.5\" y=\"-694\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">x2</text>\n",
       "</g>\n",
       "<!-- 6818277186344059326&#45;&gt;9704017862113085769 -->\n",
       "<g id=\"edge16\" class=\"edge\">\n",
       "<title>6818277186344059326&#45;&gt;9704017862113085769</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-777.9735C135.5,-767.3194 135.5,-753.5175 135.5,-741.0623\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-741.0152 135.5,-731.0153 132.0001,-741.0153 139.0001,-741.0152\"/>\n",
       "<text text-anchor=\"middle\" x=\"162\" y=\"-752\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x2048x7x7</text>\n",
       "</g>\n",
       "<!-- 758937017038444827&#45;&gt;210403017578684015 -->\n",
       "<g id=\"edge15\" class=\"edge\">\n",
       "<title>758937017038444827&#45;&gt;210403017578684015</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1208.5953C135.5,-1197.571 135.5,-1184.1615 135.5,-1172.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-1172.2297 135.5,-1162.2298 132.0001,-1172.2298 139.0001,-1172.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-1183\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x256x56x56</text>\n",
       "</g>\n",
       "<!-- 9704017862113085769&#45;&gt;ResNet/AvgPool2d[avgpool]/outputs/1385 -->\n",
       "<g id=\"edge17\" class=\"edge\">\n",
       "<title>9704017862113085769&#45;&gt;ResNet/AvgPool2d[avgpool]/outputs/1385</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-686.5953C135.5,-675.571 135.5,-662.1615 135.5,-650.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-650.2297 135.5,-640.2298 132.0001,-650.2298 139.0001,-650.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"162\" y=\"-661\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x2048x7x7</text>\n",
       "</g>\n",
       "<!-- 2760642466268956175&#45;&gt;16222374167483738286 -->\n",
       "<g id=\"edge19\" class=\"edge\">\n",
       "<title>2760642466268956175&#45;&gt;16222374167483738286</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-1034.5953C135.5,-1023.571 135.5,-1010.1615 135.5,-998.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-998.2297 135.5,-988.2298 132.0001,-998.2298 139.0001,-998.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-1009\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x512x28x28</text>\n",
       "</g>\n",
       "<!-- 17791055073794206932&#45;&gt;6818277186344059326 -->\n",
       "<g id=\"edge21\" class=\"edge\">\n",
       "<title>17791055073794206932&#45;&gt;6818277186344059326</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M135.5,-860.5953C135.5,-849.571 135.5,-836.1615 135.5,-824.4234\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"139.0001,-824.2297 135.5,-814.2298 132.0001,-824.2298 139.0001,-824.2297\"/>\n",
       "<text text-anchor=\"middle\" x=\"167.5\" y=\"-835\" font-family=\"Times\" font-size=\"10.00\" fill=\"#000000\">1x1024x14x14</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<hiddenlayer.graph.Graph at 0x7f1d0bf88080>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Resnet101\n",
    "model = torchvision.models.resnet101()\n",
    "\n",
    "# Rather than using the default transforms, build custom ones to group\n",
    "# nodes of residual and bottleneck blocks.\n",
    "transforms = [\n",
    "    # Fold Conv, BN, RELU layers into one\n",
    "    hl.transforms.Fold(\"Conv > BatchNorm > Relu\", \"ConvBnRelu\"),\n",
    "    # Fold Conv, BN layers together\n",
    "    hl.transforms.Fold(\"Conv > BatchNorm\", \"ConvBn\"),\n",
    "    # Fold bottleneck blocks\n",
    "    hl.transforms.Fold(\"\"\"\n",
    "        ((ConvBnRelu > ConvBnRelu > ConvBn) | ConvBn) > Add > Relu\n",
    "        \"\"\", \"BottleneckBlock\", \"Bottleneck Block\"),\n",
    "    # Fold residual blocks\n",
    "    hl.transforms.Fold(\"\"\"ConvBnRelu > ConvBnRelu > ConvBn > Add > Relu\"\"\",\n",
    "                       \"ResBlock\", \"Residual Block\"),\n",
    "    # Fold repeated blocks\n",
    "    hl.transforms.FoldDuplicates(),\n",
    "]\n",
    "\n",
    "# Display graph using the transforms above\n",
    "hl.build_graph(model, torch.zeros([1, 3, 224, 224]), transforms=transforms)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comment out one of these lines if you want to see the original graph before transforms are applied."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# Without simplification transforms, but include framework transforms\n",
    "# Framework transforms map PyTorch or TensorFlow graphs into a standard format\n",
    "# based, mostly, on ONNX naming conventions.\n",
    "\n",
    "# hl.build_graph(model, torch.zeros([1, 3, 224, 224]), transforms=[])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# Remove all transforms completely\n",
    "# Override both, simplicity transforms and framework transforms, to get\n",
    "# the original raw graph.\n",
    "\n",
    "# hl.build_graph(model, torch.zeros([1, 3, 224, 224]), transforms=[], framework_transforms=[])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
